package com.nineclock.approve.resolver;

import com.alibaba.fastjson.JSONObject;
import com.nineclock.approve.resolver.abs.ProcessNodeResolver;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.StartEvent;
import org.springframework.stereotype.Component;

/**
 * 开始节点的处理器
 */
@Component
public class StartNodeResolver extends ProcessNodeResolver {

    private final String type = "start";

    @Override
    public boolean support(String nodeType) {
        return nodeType.equals(type);
    }

    @Override
    public void addFlowNodeToActiviti(Process process, JSONObject curNode, JSONObject nextNode) {
        // 创建开始节点
        StartEvent startEvent = new StartEvent();
        startEvent.setId(getNodeId(curNode));
        startEvent.setName(curNode.getString("name"));
        // 添加开始节点
        process.addFlowElement(startEvent);

        // 调用父类的方法，绘制连线
        newSequenceFlow(process, curNode, nextNode);

    }
}
